<style>
fieldset{
	width: 70%;
	padding:10px;	
	margin-bottom: 5px;
}
fieldset legend{
	color: #4C4C4C;
	display: block;
	font-style: italic;
	font-weight: 600;
	height: 20px;
}
fieldset ul li{
	height: 25px;	
	line-heigt: 20px;	
}
fieldset ul li input{
	float:left;
	margin-top: 2px;
	margin-right: 5px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
	$("#frmAEBanner").submit(function(){
		var msg = "";
		if($("#name").attr("value") == ""){
			msg +="Thiếu tên nhà sản xuất.\n";
		}
		if($("#banner_logo").attr("value") == ""){
			msg +="Chưa chọn logo.";
		}
		if(msg != ""){
			alert(msg);
			return false;
		}
	});
	//xóa
	$("#btnDelete").click(function(){
		var valid= false;
		var arrChkId = $(".chkId");
		var strIDs = "";
		for(var i =0; i < arrChkId.length; i++){
			if(arrChkId.eq(i).attr("checked")){
				valid = true;
				if(strIDs!=""){
					strIDs +=","+ arrChkId.eq(i).attr("value");
				}else{
					strIDs +=arrChkId.eq(i).attr("value");
				}
				//break;
			}
		}
		
	});
});
function BrowseServer()
{

	// You can use the "CKFinder" class to render CKFinder in a page:
	var finder = new CKFinder() ;
	finder.basePath = '<?php echo PUBLIC_URL."/ckfinder/";?>' ;	// The path for the installation of CKFinder (default = "/ckfinder/").
	
	finder.selectActionFunction = function(fileUrl){
		
		document.getElementById( "banner_image" ).value = fileUrl ;
		
	}
	finder.popup() ;

	
}
</script>
<div id="r-heading">
	<img src="<?php echo PUBLIC_URL.'/admin/images/category.png';?>" alt=""/>
	<span>Quản lý banner</span>
</div>
<?php
//nếu có message thì hiển thị
if(!empty($this->message)){
	echo '<div id="message">'.$this->message.'</div>';
} 
?>
<div style="width:40%; float:left;">
	<form id="frmAEBanner" method = "post" action="">
		<div class = "row">
			<label for="name">Tên banner:</label>
			<?php if(isset($this->banner)){?>
			<input readonly="readonly" type="text" name="name" id="name" size= "50" value="<?php echo $this->banner->name;?>"/>
			<?php }else{?>
			<input type="text" name="name" id="name" size= "50"/>
			<?php }?>
		</div>
		<div class = "row">
			<label for="logo">Image:</label>
			<?php if(isset($this->banner)){?>
			<input type="text" name="image" id="banner_image" size= "50" value="<?php echo $this->banner->image;?>"/>
			
			<?php }else{?>
			<input type="text" name="image" id="banner_image" size= "50"/>
			<?php }?>
			<input type="button" class="button" value = "Chọn Ảnh" onclick="BrowseServer();"/>
			<?php if(isset($this->banner)){?>
			<img style="height: auto; width: 330px;" alt="" src="<?php echo $this->banner->image;?>"/>
			<?php }?>
		</div>
		<div class = "row">
			<label for="link">Link tới:</label>
			<?php if(isset($this->banner)){?>
			<input type="text" name="link" id="link" size= "50" value="<?php echo $this->banner->link;?>"/>
			<?php }else{?>
			<input type="text" name="link" id="link" size= "50"/>
			<?php }?>
		</div>
		<div class="row">
			<input id="btnSubmit" type="submit" value="Lưu" class="button"/>
			<input type="reset" value="Làm lại" class="button"/>
		</div>
	</form>
</div>
<div style="width: 60%; float: left;">
	<form id="frmActions" action="" method="post">
		
		
		<table class="list" cellspacing="0">
			<thead>
				<tr>
					
					<td width="20%">
						Tên banner
					</td>
					<td width="30%">
						Image	
					</td>
					<td width="30%">
						Link	
					</td>
					<td width="13%">
						Thao tác
					</td>
				</tr>
			</thead>
			<tbody>
				<?php
					$count = count($this->arrBanner);
					if($count == 0){
				?>
					<tr>
						<td colspan="4" style="color: #fc0202;">
							Chưa có banner nào trong cơ sở dữ liệu!
						</td>
					</tr>
				<?php
					}else{
						for($i = 0; $i< $count; $i++){
				?>
					<tr <?php if($i == $count - 1) echo 'class="last"';?>>
						
						<td>
							<a href="<?php echo  $this->url(array('id' => $this->arrBanner[$i]->id), 'admin_banner');?>" title="Xem thông tin banner">
								<?php
									echo $this->arrBanner[$i]->name;
								?>
							</a>
						</td>
						<td>
                                        <?php echo Helper_HtmlRender::renderImageOrFlash($this->arrBanner[$i]->image, 180, null, "");?>
								
						</td>
						<td>
							<a href="<?php echo $this->arrBanner[$i]->link;?>"><?php echo $this->arrBanner[$i]->link;?></a>
						</td>
						<td align="center">
							<a href="<?= $this->url(array('id' => $this->arrBanner[$i]->id), 'admin_banner');?>" title="Sửa thông tin nhà sản xuất">Sửa</a>
							
						</td>
					</tr>
				<?php
						}
					}
				?>
			</tbody>
			<tfoot>
				<tr>
					
					<td width="20%">
						Tên banner
					</td>
					<td width="30%">
						Image	
					</td>
					<td width="30%">
						Link	
					</td>
					<td width="13%">
						Thao tác
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</div>